package org.ielts.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	public static Date now(){
		return new Date();
	}
	
	public static long getGapDay(Date start,Date end){
		long gapValue=end.getTime()-start.getTime();
		return gapValue/1000/60/60/24;
	}
	
	public static String getGapDayRate(Date start,Date end){
		double gapValue=getGapDay(start,end);
		double gapnow=getGapDay(now(),end);
		double rate=(gapnow/gapValue)*100;
		DecimalFormat df=new DecimalFormat("0.00");
		String result="";
		if(rate>=0){
			result=df.format(rate)+"%";
		}
		else
		{
			result="已过期";
		}
		return  result;
	}
	
	public static long day2millisecond(long day){
		return day*24*60*60*1000;
	}
	
	public static Date nextMonth(){
		Calendar c=Calendar.getInstance();
		c.add(Calendar.MONTH, 1);
		return c.getTime();
	}
	public static Date nextYear(){
		Calendar c=Calendar.getInstance();
		c.add(Calendar.YEAR, 1);
		return c.getTime();
	}
	
	public static String getAsString(Date date,String fm){
		SimpleDateFormat sf=new SimpleDateFormat(fm);
		return sf.format(date);
	}
	
}
